// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import UiManager, { PanelLayer } from "./UiManager";

const { ccclass, property } = cc._decorator;

/**
 * 面板基类
 */
export enum PanelType {
    FULL_SCREEN,
    FLOAT
}

@ccclass
export default class Panel extends cc.Component {
    @property({
        tooltip: '背景节点',
        type: cc.Node
    })
    background: cc.Node = null;

    @property({
        tooltip: '内容节点',
        type: cc.Node
    })
    content: cc.Node = null;

    @property({
        tooltip: "关闭按钮",
        type: cc.Node
    })
    closeNode: cc.Node = null;

    @property({
        tooltip: "是否缓存面板"
    })
    cache: boolean = false;

    @property({
        type: cc.Enum(PanelType),
        tooltip: '面板类型：FULL_SCREEN(全屏)自适应屏幕大小、FLOAT(浮动)可停靠在任意位置'
    })
    type: PanelType = PanelType.FULL_SCREEN;

    @property({
        tooltip: '点击空白处关闭'
    })
    closeClickBlank: boolean = false;

    private _data: any = null;
    get data(): any {
        return this._data;
    }
    set data(value: any) {
        this._data = value;
    }

    private _path: string = null;
    get path(): string {
        return this._path;
    }
    set path(value: string) {
        this._path = value;
    }

    private _layer: PanelLayer = null;
    get layer(): PanelLayer {
        return this._layer;
    }
    set layer(value: PanelLayer) {
        this._layer = value;
    }

    protected onLoad(): void {
        this.closeNode.getComponent(cc.Button) && this.closeNode.addComponent(cc.Button);
        this.closeNode.on('click', this.close, this);
    }

    public beforeOpen() {

    }

    public afterOpen() {

    }

    public beforeClose() {

    }

    public afterClose() {

    }

    public refresh() {

    }

    public close() {
        UiManager.getInstance().close(this);
    }
}
